package cn.csdj.sism.service.impl;

import cn.csdj.sism.dao.ObtainEmploymentMApper;
import cn.csdj.sism.pojo.ObtainEmployment;
import cn.csdj.sism.pojo.Student;
import cn.csdj.sism.service.ObtainEmploymentService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.List;

/**
 * @author 李加
 * 2023/4/10
 */
@Service
public class ObtainEmploymentServiceImpl implements ObtainEmploymentService {
    @Autowired
    private ObtainEmploymentMApper obtainEmploymentMApper;

    /**
     * 通过id查询
     * @param id
     * @return
     */
    @Override
    public ObtainEmployment selectById(Integer id) {
        return obtainEmploymentMApper.selectById(id);
    }

    /**
     * 查询全部
     * @return
     */
    @Override
    public List<ObtainEmployment> selectAll() {
        return obtainEmploymentMApper.selectList(null);
    }

    /**
     * 添加
     * @param obtainEmployment
     * @return
     */
    @Override
    public int insertOem(ObtainEmployment obtainEmployment) {
        return obtainEmploymentMApper.insert(obtainEmployment);
    }

    /**
     * 修改
     * @param obtainEmployment
     * @return
     */
    @Override
    public int updateOem(ObtainEmployment obtainEmployment) {
        return obtainEmploymentMApper.updateById(obtainEmployment);
    }

    /**
     * 通过id删除
     * @param id
     * @return
     */
    @Override
    public int dalectOemById(Integer id) {
        return obtainEmploymentMApper.deleteById(id);
    }

    /**
     * 分页查询
     * @param current
     * @param pageSize
     * @return
     */
    @Override
    public IPage<ObtainEmployment> selectByPage(Integer current, Integer pageSize) {
        //        Page(当前页码，页面大小);
        IPage<ObtainEmployment> page = new Page(current,pageSize);
        obtainEmploymentMApper.selectPage(page,null);
        return page;
    }

    @Override
    public IPage<ObtainEmployment> selectPagesByCondition(HashMap condition) {
        IPage<ObtainEmployment> page=new Page<>((Integer) condition.get("current"),(Integer) condition.get("pageSize"));
        LambdaQueryWrapper<ObtainEmployment> lqw = new LambdaQueryWrapper<>();
        if (!StringUtils.isEmpty(condition.get("studentId"))){
            lqw.like(ObtainEmployment::getStudentId,condition.get("studentId"));
        }
        if (!StringUtils.isEmpty(condition.get("obtainEmpStatus"))){
            lqw.eq(ObtainEmployment::getObtainEmpStatus,condition.get("obtainEmpStatus"));
        }
        if (!StringUtils.isEmpty(condition.get("isProvideOffer"))){
            lqw.eq(ObtainEmployment::getIsProvideOffer,condition.get("isProvideOffer"));
        }
        obtainEmploymentMApper.selectPage(page,lqw);
        return page;
    }
}
